import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/HomeView.vue";
import Cookies from "js-cookie";

Vue.use(VueRouter);

const routes = [
  // {
  //   path: "/login",
  //   name: "Login",
  //   component: () => import("../views/login.vue"),
  // },
  {
    path: "/",
    name: "home",
    component: HomeView,
    redirect: "/index",
    children: [
      {
        path: "index", //注意此处不能加 /
        name: "homePage",
        component: () => import("../views/home/index.vue"), //动态加载小区管理页面
      },
      // 收费设置
      // 收费项管理
      {
        path: "ChargeItemManagement",
        name: "ChargeItemManagement",
        component: () =>
          import("../views/FeeCollectingManagement/ChargeItemManagement.vue"),
      },
      // 租售合同管理
      {
        path: "LeaseSaleContractManagement",
        name: "LeaseSaleContractManagement",
        component: () =>
          import(
            "../views/FeeCollectingManagement/LeaseSaleContractManagement.vue"
          ),
      },
      // 收费数据生成
      {
        path: "ChargeDataGeneration",
        name: "ChargeDataGeneration",
        component: () =>
          import("../views/FeeCollectingManagement/ChargeDataGeneration.vue"),
      },
      // 抄表数据管理
      {
        path: "MeterReadingDataGeneration",
        name: "MeterReadingDataGeneration",
        component: () =>
          import(
            "../views/FeeCollectingManagement/MeterReadingDataGeneration.vue"
          ),
      },
      // 收费订单数据
      {
        path: "ChargeOrderData",
        name: "ChargeOrderData",
        component: () =>
          import("../views/FeeCollectingManagement/ChargeOrderData.vue"),
      },
      // 费用催缴
      {
        path: "ChargeCall",
        name: "ChargeCall",
        component: () =>
          import("../views/FeeCollectingManagement/ChargeCall.vue"),
      },
      // 待生成的费用
      {
        path: "ExpenseIncurred",
        name: "ExpenseIncurred",
        component: () =>
          import("../views/FeeCollectingManagement/ExpenseIncurred.vue"),
      },
      // 业主信息
      {
        path: "OwnerMassage",
        name: "OwnerMassage",
        component: () => import("../views/OwnerManagement/OwnerMassage.vue"),
      },
      {
        path: "OwnerMassageInfo",
        name: "OwnerMassageInfo",
        component: () =>
          import("../views/OwnerManagement/OwnerMassageInfo.vue"),
      },
      {
        path: "PersonalCenter",
        name: "PersonalCenter",
        component: () => import("../views/Personal/PersonalCenter.vue"),
      },
      {
        path: "desposit", //注意此处不能加 /
        name: "despositManagement",
        component: () =>
          import("../views/chargeManagement/Depositmanagement.vue"), //动态加载押金管理页面
      },
      {
        path: "controller", //注意此处不能加 /
        name: "controllerMoney",
        component: () =>
          import("../views/chargeManagement/ControllerCounter.vue"), //动态加载押金管理页面
      },
      {
        path: "temporary", //注意此处不能加 /
        name: "temporaryCharges",
        component: () =>
          import("../views/chargeManagement/TemporaryCharges.vue"), //动态加载押金管理页面
      },
      {
        path: "premoney", //注意此处不能加 /
        name: "prepayment",
        component: () => import("../views/chargeManagement/prepayment.vue"), //动态加载押金管理页面
      },
      {
        path: "shops", //注意此处不能加 /
        name: "shopManagement",
        component: () => import("../views/AssetsManageMent/ShopManagement.vue"), //动态加载押金管理页面
      },
    ],
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

// // 全局路由守卫，实现访问资源时判断是否登录，登陆就放行。没有就登录。跳转到登录页面
// router.beforeEach((to, from, next) => {
//   if (to.path == "/login" || to.path == "/register") {
//     next(); // 放行
//   } else {
//     const username = Cookies.get("username");
//     if (username == null || username == undefined || username == "") {
//       router.push("/login");
//     } else {
//       //放行
//       next();
//     }
//   }
// });

export default router;
